package org.acompanhamento;

import java.util.Iterator;

import jmine.tec.environment.db.DBEnvironmentHolder;
import jmine.tec.test.testcase.BOBaseTestCase;

import org.hibernate.EntityMode;
import org.hibernate.metadata.ClassMetadata;

import bancosys.tec.utils.reflection.ReflectionUtils;

/**
 * 
 * @author lundberg
 *
 */
public class SampleDataCreator {

	public void createData(String prefix) {
		Iterator<?> it = DBEnvironmentHolder.getInstance().getEnvironment().getHelper().getSessionFactory().getAllClassMetadata().values().iterator();
		while(it.hasNext()) {
			ClassMetadata meta = (ClassMetadata) it.next();
			String entityClassName = meta.getMappedClass(EntityMode.POJO).getName();
			if(entityClassName.startsWith(prefix)) {
				try {
					BOBaseTestCase<?> testCase = (BOBaseTestCase<?>) ReflectionUtils.findClass(entityClassName + "Test").getConstructor(new Class[]{}).newInstance();
					testCase.getSavedTestData();
				} catch (Exception e) {
					e.printStackTrace();
					throw new RuntimeException(e);
				}
			}
		}
	}

}
